/*	
 * Authors: Ken YANG <spng.yang@gmail.com>
 * 	
 * Mammoth client main program
 *
 * Copyright (C) 2007-2008 Ken YANG
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation, version 2. 
 * THIS SOFTWARE COMES "AS IS" WITHOUT ANY WARRANTIES.
 */

#if !defined (_HAVE_THREADS_H)
#define _HAVE_THREADS_H 1


#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "effective_io.h"


/* 
 * Because thread can not use errno to report error 
 * messages as most other POSIX functions, we define 
 * two error macro to output error messages, which 
 * you can use them as if they are real functions
 * */
#define err_abort(code,text) do{	\
	fprintf(stderr,"%s at \"%s\":%d: %s \n",	\
			text, __FILE__, __LINE__, strerror(code)); \
	abort();	\
}while(0)


/* pthread api wrapper */
int Pthread_create(pthread_t *tid, const pthread_attr_t *attr,
		void *(*start_routine)(void *), void *args);

void Pthread_detach(pthread_t tid);
void Pthread_key_create(pthread_key_t *key, void (*destructor)(void*));
void Pthread_once(pthread_once_t *ptr, void (*func)(void));
void Pthread_setspecific(pthread_key_t key, const void *value);
void Pthread_mutex_lock(pthread_mutex_t *mutex);
void Pthread_mutex_unlock(pthread_mutex_t *mutex);





#endif
